<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
	String path =request.getContextPath();
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript"
	src="<%=path%>/js/validatorTool.js"></script>
<script language="javascript" type="text/javascript">

     	//全选
    	function ChkAllClick(sonName, cbAllId){
    		var arrSon = document.getElementsByName(sonName);
    	 	var cbAll = document.getElementById(cbAllId);
    	 	var tempState=cbAll.checked;
    	 	for(i=0;i<arrSon.length;i++) {
    	  		if(arrSon[i].checked!=tempState){
    	        	arrSon[i].click();
    	 		}
    		}
    	}

    	// --子项复选框被单击---
    	function ChkSonClick(sonName, cbAllId) {
    		var arrSon = document.getElementsByName(sonName);
    	 	var cbAll = document.getElementById(cbAllId);
    	 	for(var i=0; i<arrSon.length; i++) {
    	    	if(!arrSon[i].checked) {
    	     		cbAll.checked = false;
    	     		return;
    	     	}
    	 	}
    	 	cbAll.checked = true;
    	}

    	// --反选被单击---
    	function ChkOppClick(sonName){
    		var arrSon = document.getElementsByName(sonName);
    	 	for(i=0;i<arrSon.length;i++) {
    	  		arrSon[i].click();
    	 	}
    	}

    	
		//查询订单
		function qryConfirm(){
			var beginDate=trim(document.getElementById("qryOrderBeginDate").value);
			var endDate=trim(document.getElementById("qryOrderEndDate").value);
			if(beginDate==""){
				alert("请输入订单起始日期");
				return;
			}
			if(endDate==""){
				alert("请输入订单终止日期");
				return;
			}
			var tempBeginDate=new Date(beginDate.replace(/\-/g, "\/"));
			var tempEndDate=new Date(endDate.replace(/\-/g, "\/"));
			if(tempBeginDate>tempEndDate){
				alert("订单起始日期不得晚于订单终止日期");
				return ;
			}
			form1.submit();
		}
		
        //接受订单
        function acceptOrder(){
        	var arrSon = document.getElementsByName("checkBox");
        	var row=0;
        	for(i=0;i<arrSon.length;i++) {
        		if(arrSon[i].checked){
	        		var pkOrder=arrSon[i].id;
	    	  		var status=trim(document.getElementById("status_"+pkOrder).value);
	    	  		if(status==1 ){
	    	  			row=row+1;
		  				document.getElementById("pk_"+pkOrder).value=pkOrder;
						// 设置页面状态
		  				var qryconfirmStatus = document.getElementById("status_"+pkOrder);
			        	qryconfirmStatus.value = 2;
	    	  		}
    	  		}
    		}
    		if(row==0){
				alert("请选择响应状态为\"待卖方确认\"的订单");
				return ;
    		}else{
	        	form2.action="<%=path%>/order/acceptOrder";
	        	//alert("操作成功！");
	        	form2.submit();
    		}
        }
        
        //拒绝订单
        function rejectOrder(){
        	var arrSon = document.getElementsByName("checkBox");
        	var row=0;
        	for(i=0;i<arrSon.length;i++) {
    	  		if(arrSon[i].checked){
    	  			var pkOrder=arrSon[i].id;
        	  		var status=trim(document.getElementById("status_"+pkOrder).value);
        	  		if(status==1){
        	  			row=row+1;
    	  				document.getElementById("pk_"+pkOrder).value=pkOrder;
        	  		}
    	 		}
    		}
    		if(row==0){
				alert("请选择响应状态为\"待卖方确认\"的订单");
				return ;
    		}else{
        		var rejectReason=prompt("请输入拒绝原因：","");
        		if(trim(rejectReason)==null || trim(rejectReason)==""){
					alert("拒绝，必须输入拒绝原因。");
					return ;
            	}else{
	  				document.getElementById("rejectReason").value=rejectReason;
		        	form2.action="<%=path%>/order/rejectOrder";
		        	//alert("操作成功！");
		        	form2.submit();
    			}
        	}
        }
		
		//提交修改订单
        function commitUptOrder(){
        	var arrSon = document.getElementsByName("checkBox");
        	var row=0;
        	for(i=0;i<arrSon.length;i++) {
    	  		if(arrSon[i].checked){
        	  		var pkOrder=arrSon[i].id;
        	  		var status=trim(document.getElementById("status_"+pkOrder).value);
        	  		if(status==4){
        	  			row=row+1;
        	  			var pkWebOrder=document.getElementById("checkBox_"+pkOrder).value
   		 				document.getElementById("pk_"+pkOrder).value=pkWebOrder;
        	  		}
    	 		}
    		}
    		if(row==0){
				alert("请选择响应状态为\"卖方变更中\"的订单");
				return ;
    		}else{
	        	form2.action="<%=path%>/order/commitUptOrder";
	        	//alert("操作成功！");
	        	form2.submit();
    		}
        }
        
        function clearStatus(){
        	document.getElementById("qryconfirmStatus").value="";
        }
        
     </script>

</head>
<body class="fullbody">
<div class="context">
	<div class="position">
		<div class="tposi">当前位置： <a href="javascript:changeMenu(1,'<%=path%>/infopub/pubmain?menuid=1');"class="linkstyle">首页</a>&nbsp;&gt;&gt;&nbsp; 
									 <a href="javascript:changeMenu(3,'');" class="linkstyle">我的订单\合同</a>&nbsp;&gt;&gt;&nbsp; 
									 <span class="curposition">订单确认</span>
		</div>
		<div class="help">
			<a href="javascript:void(null);" onclick="doHelp('<%=request.getContextPath()%>/help/html/DDQR.html');" class="linkstyle">帮助</a>
		</div>
	</div>
	<div class="margin8"></div>
	<div class="subpage_title">
		<div class="title_index"><img
			src="<%=path%>/images/common/dot03.gif" alt="" border="0" />&nbsp;订单确认
		</div>
	</div>
	<div class="margin20"></div>
	<div class="subpage_bidlist">
		<div>
			<div>
				<div class="title_index">
					<div class="subpage_search">
						<form name="form1" action="<%=path%>/order/qryConfirmlist" method="post">
							<table border="0" cellpadding="0" cellspacing="0" class="searchtable">
								<tr>
									<td valign="middle" class="w_1">采购订单号：</td>
									<td valign="middle" class="w_2"><input id="qryOrderNo"
										name="qryOrderNo" type="text" value="${qryOrderNo}"
										class="searchtext" /></td>
									<td valign="middle" class="w_1">采购公司：</td>
									<td valign="middle" class="w_2"><input id="qryPurCorp"
										name="qryPurCorp" type="text" value="${qryPurCorp}"
										class="searchtext" /></td>
								</tr>
								<tr>
									<td valign="middle" class="w_1">订单日期：</td>
									<td valign="middle" class="w_2"><input id="qryOrderBeginDate"
										name="qryOrderBeginDate" type="text" value="${qryOrderBeginDate}"
										onclick="return showCalendar('qryOrderBeginDate', 'y-mm-dd');"
										readonly="readonly" class="searchdate" />&nbsp;至&nbsp; <input
										id="qryOrderEndDate" name="qryOrderEndDate" type="text"
										value="${qryOrderEndDate}"
										onclick="return showCalendar('qryOrderEndDate', 'y-mm-dd');"
										readonly="readonly" class="searchdate" /></td>
									<td valign="middle" class="w_1">响应状态：</td>
									<td valign="middle" class="w_2"><select class="searchtext"
										name="qryconfirmStatus" id="qryconfirmStatus">
										<option value="">全部</option>
										<option value="1"
											<c:if test="${1==qryconfirmStatus}">selected</c:if>>待卖方确认</option>
										<option value="2"
											<c:if test="${2==qryconfirmStatus}">selected</c:if>>接受</option>
										<option value="3"
											<c:if test="${3==qryconfirmStatus}">selected</c:if>>拒绝</option>
										<option value="4"
											<c:if test="${4==qryconfirmStatus}">selected</c:if>>卖方变更中</option>
										<option value="5"
											<c:if test="${5==qryconfirmStatus}">selected</c:if>>卖方已变更</option>
										<option value="6"
											<c:if test="${6==qryconfirmStatus}">selected</c:if>>买方已确认</option>
									</select></td>
								</tr>
								<tr>
									<td valign="middle" class="w_1">产品名称：</td>
									<td valign="middle" class="w_2"><input id="qryProdName"
										name="qryProdName" type="text" value="${qryProdName}"
										class="searchtext" /></td>
								</tr>
								<tr>
									<td colspan="4">&nbsp;</td>
								</tr>
								<tr>
									<td valign="middle" colspan="4" align="center"><input
										type="button" class="btnscs" value="查询" onclick="qryConfirm()" />&nbsp;&nbsp;
									<input type="button" class="btnscs" value="取消" onclick="resetData();clearStatus()"/>&nbsp;&nbsp;</td>
								</tr>
							</table>
						</form>
					</div>
				<div>
				<form name="form2" action="<%=path%>/order/qryConfirmlist" method="post">
				<input type="hidden" value="" name="type" id="type" /> <input
					type="hidden" value="" name="rejectReason" id="rejectReason" />
				<table class="tableCss" cellpadding="0" cellspacing="0">
					<tr class="titleTr">
						<th width="35px">
							<input type="checkbox" name="chkAll" id="chkAll" onclick="ChkAllClick('checkBox','chkAll')" />
						</th>
						<th width="160px">采购订单号</th>
						<th width="212px">采购公司</th>
						<th width="146px">订单日期</th>
						<th width="186px">响应状态</th>
						<th width="61px" class="th1">浏览</th>
					</tr>
					<c:if test="${orderForms!=null}">
						<c:forEach items="${orderForms}" var="orderForm" varStatus="index">
							<c:if test="${orderForm.index%2==1}">
								<tr align="left" class="contTr-old"  >
							</c:if>
							<c:if test="${orderForm.index%2==0}">
								<tr align="left" class="contTr-even">
							</c:if>
								<td class="td1">
									<input type="hidden" id="pk_${orderForm.pkOrder}" name="selected" value="" />
									<input type="hidden" id="ts" name="ts" value="${orderForm.ts}" /> 
									<input type="hidden" id="pk_ordersz" name="pk_ordersz" value="${orderForm.pkOrder}" /> 
									<input type="checkbox" id="${orderForm.pkOrder}" name="checkBox" /> 
									<input type="hidden" id="checkBox_${orderForm.pkOrder}" value="${orderForm.pkWebOrder}" />
								</td>
								<td class="td1"><a href="<%=path%>/order/browseOrder?orderPk=${orderForm.pkOrder}&pkWebOrder=${orderForm.pkWebOrder}&qryconfirmStatus=${orderForm.responseStatus}"
									class="linkstyle">${orderForm.billNo}</a></td>
								<td class="td1">${orderForm.purCorpName}</td>
								<td class="td1">${orderForm.ordeDate}</td>
								<td class="td1">
									<input type="hidden" value="${orderForm.responseStatus}" id="status_${orderForm.pkOrder}" name="qryconfirmStatus"/>
									<c:if test="${1==orderForm.responseStatus}">待卖方确认</c:if>
									<c:if test="${2==orderForm.responseStatus}">接受</c:if>
									<c:if test="${3==orderForm.responseStatus}">拒绝</c:if>
									<c:if test="${4==orderForm.responseStatus}">卖方变更中</c:if>
									<c:if test="${5==orderForm.responseStatus}">卖方已变更</c:if>
									<c:if test="${6==orderForm.responseStatus}">买方已确认</c:if>
								</td>
								<td class="td1">
								<a href="<%=path%>/order/browseOrder?orderPk=${orderForm.pkOrder}&pkWebOrder=${orderForm.pkWebOrder}&qryconfirmStatus=${orderForm.responseStatus}" class="linkstyle">浏览</a>
								<!-- 
									<c:if test="${1==orderForm.responseStatus ||4==orderForm.responseStatus}">
										<a href="<%=path%>/order/editOrder?orderPk=${orderForm.pkOrder}&pkWebOrder=${orderForm.pkWebOrder}&qryconfirmStatus=${orderForm.responseStatus}" class="linkstyle">变更</a>
									</c:if> 
									
									<c:if test="${2==orderForm.responseStatus ||3==orderForm.responseStatus||5==orderForm.responseStatus||6==orderForm.responseStatus}">
										<a href="<%=path%>/order/browseOrder?orderPk=${orderForm.pkOrder}&pkWebOrder=${orderForm.pkWebOrder}&qryconfirmStatus=${orderForm.responseStatus}" class="linkstyle">浏览</a>
									</c:if>
									 -->
								</td>
							</tr>
						</c:forEach>
					</c:if>
				</table>
				</form>
				</div>
				<div class="margin8"></div>
				<div>
					<table width="600" align="center" border="0" cellspacing="0"
						cellpadding="0">
						<tr id="order_confirm" align="center">
							<td><input type="button" class="btnscs" value="接受"
								onclick="acceptOrder()" /> &nbsp;&nbsp;&nbsp;&nbsp; <input
								type="button" class="btnscs" value="拒绝" onclick="rejectOrder()" />
								<!-- 
							&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" class="btnscs"
								value="变更提交" onclick="commitUptOrder()" />
								 -->
								</td>
						</tr>
					</table>
				</div>
				</div>
			<div class="margin20"></div>
			</div>
		</div>
</div>
	<div class="margin8"></div>
		<div class="margin8">
			<table align="left">
				<tr class="title">
					<td>
					<div id="message" class="msgcolor">${system_err_msg}</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>
